package com.freework.context.web.spring;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

import org.springframework.http.HttpInputMessage;
import org.springframework.http.HttpOutputMessage;
import org.springframework.http.MediaType;
import org.springframework.http.converter.AbstractHttpMessageConverter;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.util.FileCopyUtils;

import com.alibaba.fastjson.JSON;
import com.freework.freedbm.base.DTO;
public class JSONHttpMessageConverter extends
		AbstractHttpMessageConverter<Object> {
	
	public JSONHttpMessageConverter() {  
        super(new MediaType("text", "javascript",Charset.forName("GB2312")));  
    }  
	@Override
	protected Object readInternal(Class<? extends Object> clazz,
			HttpInputMessage inputMessage) throws IOException,
			HttpMessageNotReadableException {
      
		return null;
	}

	@Override
	protected boolean supports(Class<?> clazz) {
		return clazz!=String.class;
	}

	@Override
	protected void writeInternal(Object t, HttpOutputMessage outputMessage)
			throws IOException, HttpMessageNotWritableException {
		String s=JSON.toJSONString(t);
		FileCopyUtils.copy(s, new OutputStreamWriter(outputMessage.getBody(), "GB2312"));
	}
	
	

	
	public boolean canRead(Class<?> clazz, MediaType mediaType){
		 return false;
	 }
}
